{% assign filename = page.path | split: "/" | last %}
{% if page.name and page.name != filename %}
  {% assign title = page.name %}
{% elsif page.title %}
  {% assign title = page.title %}
{% else %}
  {% assign title = nil %}
{% endif %}

{% assign title = title | xml_escape %}

{% assign fulltitle = "" | split: "," %}
{% if title and title != "" %}
  {% assign fulltitle = fulltitle | push: title %}
{% endif %}
{% if site.title and site.title != "" %}
  {% assign fulltitle = fulltitle | push: site.title %}
{% endif %}
{% assign fulltitle = fulltitle | join: " | " %}

{% assign subtitle = site.subtitle %}

{% assign description = page.description | default: site.description %}
{% if site.subtitle %}
  {% capture description -%}
    {{ site.subtitle }}. {{ description }}
  {%- endcapture %}
{% endif %}
{% capture url -%}
  {{ site.url }}{{ site.baseurl }}
{%- endcapture %}

{% assign description = description | xml_escape %}

{% assign png = "images/icon.png" | file_exists %}
{% assign jpg = "images/icon.jpg" | file_exists %}
{% assign icon = png | default: jpg | relative_url %}

{% assign jpg = "images/share.jpg" | file_exists %}
{% assign png = "images/share.png" | file_exists %}
{% assign share = jpg | default: png | relative_url %}

{% assign published = page.date | date_to_xmlschema %}
{% assign updated = page.last_modified_at | date_to_xmlschema %}

{% assign feed = "feed.xml" | absolute_url %}

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>{{ fulltitle }}</title>

<link rel="icon" href="{{ icon }}">

<meta name="title" content="{{ title }}">
<meta name="description" content="{{ description }}">

<meta property="og:title" content="{{ title }}">
<meta property="og:site_title" content="{{ site.title | xml_escape }}">
<meta property="og:description" content="{{ description }}">
<meta property="og:url" content="{{ url }}">
<meta property="og:image" content="{{ share }}">
<meta property="og:locale" content="en_US">

<meta property="twitter:title" content="{{ title }}">
<meta property="twitter:description" content="{{ description }}">
<meta property="twitter:url" content="{{ url }}">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:image" content="{{ share }}">

{% if page.author %}
  <meta name="author" content="{{ page.author | xml_escape }}">
  <meta property="og:type" content="article">
  <meta property="og:updated_time" content="{{ updated }}">
  <meta property="article:published_time" content="{{ published }}">
  <meta property="article:modified_time" content="{{ updated }}">
  <meta name="revised" content="{{ updated }}">
{% else %}
  <meta property="og:type" content="website">
{% endif %}

<script type="application/ld+json">
  {
    "@context": "https://schema.org",
    {% if page.author %}
      "@type": "BlogPosting",
      "author": { "@type": "Person", "name": "{{ title }}" },
      "datePublished": "{{ published }}",
      "dateModified": "{{ updated }}",
    {% else %}
      "@type": "WebSite",
    {% endif %}
    "name": "{{ title }}",
    "description": "{{ description }}",
    "headline": "{{ title }}",
    "publisher": {
      "@type": "Organization",
      "logo": { "@type": "ImageObject", "url": "{{ icon }}" }
    },
    "url": "{{ url }}"
  }
</script>

<link rel="alternate" type="application/rss+xml" href="{{ feed }}">
